/**
 * 
 */
package com.fox.webapp.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.fox.webapp.utils.Constant;

/**
 * @author yockii
 *
 */
public class AdminLoginInterceptor extends HandlerInterceptorAdapter {

	/* (non-Javadoc)
	 * @see org.springframework.web.servlet.handler.HandlerInterceptorAdapter#preHandle(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.Object)
	 */
	@Override
	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {
		if(request.getSession(true).getAttribute(Constant.SESSION_ADMIN) == null && !request.getRequestURI().contains("login.yockii")){
			response.sendRedirect(request.getContextPath() + "/login.html");
			return false;
		}
		return true;
	}

}
